﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using EmployeeTracker.Model;
using System.Data;
using EmployeeTracker.Helper;
using System.Data.SqlClient;
using System.Text;
using EmployeeTracker.DataLayer;
using EmployeeTracker.Helper;


namespace EmployeeTracker.Gateway
{
    public class CountryGateway
    {
       
        public ObservableCollection<Country> GetAllcountries()
        {
            ObservableCollection<Country> allCountry = new ObservableCollection<Country>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCountryList());
            if (dt.Rows.Count <= 0)
            {
                return allCountry;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allCountry.Add(new Country()
                {
                    CountryId = dataRow["Country_ID"].ToString(),
                    CountryName = dataRow["Country_Name"].ToString(),
                    CountryNationality=dataRow["Country_Nationality"].ToString()
                });
            }
            return allCountry;
        }

        public void SaveNewCountryToDatabase(string country,string nationality,int eu,int migration)
        {
            string query= QueryProvider.MakeSQLQueryToInsertCountryToDatabase(country, nationality, eu, migration);
            DBHelper.ExecuteSqlQuery(query);
        }


    }
}
